<template>
  <div class="main-scroll">
    <headerc :title="title"></headerc>
    <el-card class="box-card">
      <!-- <div class="title-text">数据筛选</div> -->
      <div style="padding: 10px;" class="c-filter">
        <el-form
          :inline="true"
          :model="findMsg"
          class="demo-form-inline"
          label-width="70px"
        >
          <el-form-item label="员工姓名">
            <el-input
              v-model="findMsg.emplName"
              placeholder="员工姓名"
            ></el-input>
          </el-form-item>
          <el-form-item label="所属部门">
            <el-input v-model="findMsg.dept" placeholder="输入部门"></el-input>
          </el-form-item>
          <el-form-item label="二级部门">
            <el-input
              v-model="findMsg.secondDept"
              placeholder="输入二级部门"
            ></el-input>
          </el-form-item>
          <el-form-item label="所属班组">
            <el-input v-model="findMsg.team" placeholder="输入班组"></el-input>
          </el-form-item>
          <el-form-item label="活动类型">
            <el-select
              v-model="findMsg.activityType"
              placeholder="请选择"
              @change="findType"
            >
              <el-option label="十个一活动" value="1"></el-option>
              <el-option label="应急演练" value="2"></el-option>
              <el-option label="岗位练兵" value="3"></el-option>
              <el-option label="技能比武" value="4"></el-option>
              <el-option label="知识竞赛" value="5"></el-option>
              <el-option label="安全活动" value="6"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="参与角色">
            <el-select
              v-model="findMsg.participatingRole"
              placeholder="请选择"
              @change="findRole"
            >
              <el-option label="参与人员" value="1"></el-option>
              <el-option label="观摩人员" value="2"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="活动时间">
            <el-date-picker
              v-model="findMsg.activityDate"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            >
            </el-date-picker>
          </el-form-item>
          <el-row>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="query"
                >查询</el-button
              >
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="reset">清除查询条件</el-button>
            </el-form-item>
          </el-row>
        </el-form>
      </div>
    </el-card>
    <el-card>
      <!-- <div class="main-seting">
        <div> -->
      <div class="title-text">数据列表</div>
      <el-button
        v-auth="'C03002'"
        style="
          float: right;
          margin-right: 20px;
          margin-bottom: 20px;
          margin-top: 20px;
        "
        icon="el-icon-download"
        @click="exportExcel"
        >导出</el-button
      >

      <el-button
        v-auth="'C03001'"
        type="primary"
        style="
            float: right;
            margin-right: 20px;
            margin-bottom: 20px;
            margin-top: 20px;
          "
        icon="el-icon-plus"
        @click="dialogVisible = true"
        >添加</el-button
      >
      <div style="margin:20px">
        <el-table
          :data="activityList"
          border
          style="width: 100%"
          :header-cell-style="{ background: '#F6F7FB' }"
        >
          <el-table-column
            type="index"
            :index="indexAdd"
            label="序号"
            width="50"
          >
          </el-table-column>
          <el-table-column prop="dept" label="部门">
            <template slot-scope="scope">
              <p>{{ scope.row.dept }}</p>
            </template>
          </el-table-column>
          <el-table-column prop="secondDept" label="二级部门">
            <template slot-scope="scope">
              <p>{{ scope.row.secondDept }}</p>
            </template>
          </el-table-column>
          <el-table-column prop="team" label="班组">
            <template slot-scope="scope">
              <p>{{ scope.row.team }}</p>
            </template>
          </el-table-column>
          <el-table-column prop="emplName" label="姓名">
            <template slot-scope="scope">
              <p>{{ scope.row.emplName }}</p>
            </template>
          </el-table-column>
          <el-table-column prop="activityTime" label="活动时间">
            <template slot-scope="scope">
              <p>{{ scope.row.activityTime | formatDate("yyyy-MM-dd") }}</p>
            </template>
          </el-table-column>
          <el-table-column prop="activityType" label="活动类型">
            <template slot-scope="scope">
              <p>{{ typefun(scope.row.activityType) }}</p>
            </template>
          </el-table-column>
          <el-table-column prop="content" :show-overflow-tooltip='true' label="活动内容" width="140">
            <template slot-scope="scope">
              <p>{{ scope.row.content }}</p>
            </template>
          </el-table-column>
          <el-table-column prop="participatingRole" label="安全活动参与角色">
            <template slot-scope="scope">
              <p>{{ rolefun(scope.row.participatingRole) }}</p>
            </template>
          </el-table-column>
          <el-table-column prop="level" label="比武名次">
            <template slot-scope="scope">
              <p>{{ rankingfun(scope.row.ranking) }}</p>
            </template>
          </el-table-column>
          <el-table-column prop="score" label="得分情况">
            <template slot-scope="scope">
              <p>{{ scope.row.score }}</p>
            </template>
          </el-table-column>
          <el-table-column prop="remark" label="备注" :show-overflow-tooltip='true'>
            <template slot-scope="scope">
              <p>{{ scope.row.remark }}</p>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <el-pagination
        background
        layout="prev, pager, next"
        :page-size="pageSize"
        :total="total"
        :hide-on-single-page="total < 10"
        @current-change="currentChange"
        class="pagination"
      >
      </el-pagination>
    </el-card>
    <el-dialog title="填报须知" :visible.sync="dialogVisible" width="50%">
      <div class="notice">
        <p>一、填报要求：</p>
        <p>1、活动时间真实填报。</p>
        <p>
          2、活动形式包括“十个一“活动、应急演练、岗位练兵、技能比武、知识竞答等。
        </p>
        <p>3、内容要求简洁、准确表达活动内容。</p>
        <p>二、积分标准</p>
        <p>
          1、观摩安全活动、岗位练兵或技能比武，记0.5分。
        </p>
        <p>2、参与安全活动、岗位练兵、技能比武记1分。</p>
        <p>
          3、参加公司级组织的技能比武等活动取得名次者第一名记5分、第二名记3分、第三名记2分、被通报表扬者记1分。
        </p>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button
          type="primary"
          @click="
            dialogVisible = false;
            dialogVisible2 = true;
          "
        >
          确 定
        </el-button>
      </span>
    </el-dialog>
    <el-dialog title="添加" :visible.sync="dialogVisible2" width="50%">
      <el-form
        ref="addForm"
        :model="addForm"
        :rules="rules"
        label-width="200px"
      >
        <el-form-item label="活动时间:" prop="activityTime" required>
          <el-date-picker
            v-model="addForm.activityTime"
            value-format="yyyy-MM-dd"
            type="date"
            placeholder="请选择日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="活动类型:" prop="activityType" required>
          <el-select
            v-model="addForm.activityType"
            placeholder="请选择"
            @change="changeType"
          >
            <el-option label="十个一活动" value="1"></el-option>
            <el-option label="应急演练" value="2"></el-option>
            <el-option label="岗位练兵" value="3"></el-option>
            <el-option label="技能比武" value="4"></el-option>
            <el-option label="知识竞赛" value="5"></el-option>
            <el-option label="安全活动" value="6"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="活动内容:" prop="content" required>
          <el-input
            v-model="addForm.content"
            type="textarea"
            :rows="4"
            placeholder="请填写"
            maxlength="200"
            show-word-limit>
        </el-input>
        </el-form-item>
        <el-form-item label="活动参与角色:" prop="participatingRole">
          <el-select
            v-model="addForm.participatingRole"
            placeholder="请选择"
            @change="changeRole"
          >
            <el-option label="参与人员" value="1"></el-option>
            <el-option label="观摩人员" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="技能比武名次:" prop="ranking">
          <el-select
            v-model="addForm.ranking"
            placeholder="请选择"
            @change="changeRanking"
          >
            <el-option label="公司第一名" value="1"></el-option>
            <el-option label="公司第二名" value="2"></el-option>
            <el-option label="公司第三名" value="3"></el-option>
            <el-option label="通报表扬" value="4"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注:" prop="remark">
          <el-input 
          v-model="addForm.remark" 
          placeholder="请填写"
          type="textarea"
          :rows="4"
          maxlength="50"
          show-word-limit>
        </el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="addActivity">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { findUser } from '@/api/index'
import { exportMethod } from '@/utils/utils'
import headerc from '@/components/header.vue'
import { addActivity, activityList } from '@/api/personal-files'
export default {
  components: {
    headerc,
  },
  data() {
    return {
      title: "安全活动与技术比武记录",
      findMsg: {
        activityStartTime: "",
        activityEndTime: "",
        activityType: "",
        activityTypeNum: "",
        dept: "",
        emplName: "",
        participatingRole: "",
        participatingRoleNum: "",
        secondDept: "",
        team: "",
        activityDate: "",
      },
      addForm: {
        activityTime: "",
        activityType: "",
        activityTypeNum: "",
        content: "",
        participatingRole: "",
        participatingRoleNum: "",
        ranking: "",
        rankingNum: "",
        remark: "",
      },
      rules: {
        activityTime: [
          { required: true, message: "请选择日期", trigger: "change" },
        ],
        activityType: [
          { required: true, message: "请选择活动类型", trigger: "change" },
        ],
        content: [
          { required: true, message: "请填写活动内容", trigger: "blur" },
        ],
        participatingRole: [
          { required: true, message: "请选择活动参与角色", trigger: "change" },
        ]
      },
      dialogVisible: false,
      dialogVisible2: false,
      activityList: [],
      pageNo: 1, // 分页页码
      pageSize: 10, // 每页条数
      total: 0,
    };
  },
  created() {
    this.getActivityList();
  },
  methods: {
    exportExcel() {
      const data = {
        pageNo: this.pageNo,
        pageSize: 5000,
        activityStartTime: this.findMsg.activityDate[0],
        activityEndTime: this.findMsg.activityDate[1],
        activityType: this.findMsg.activityTypeNum,
        dept: this.findMsg.dept,
        emplName: this.findMsg.emplName,
        participatingRole: this.findMsg.participatingRoleNum,
        secondDept: this.findMsg.secondDept,
        team: this.findMsg.team,
        ranking:this.findMsg.rankingNum
      }
      exportMethod('activity', data, '安全活动与技能比武记录')
    },
    typefun(data) {
      if (data == 1) {
        return "十个一活动";
      } else if (data == 2) {
        return "应急演练";
      } else if (data == 3) {
        return "岗位练兵";
      } else if (data == 4) {
        return "技能比武";
      } else if (data == 5) {
        return "知识竞赛";
      } else if (data == 6) {
        return "安全活动";
      }
    },
    rolefun(data) {
      if (data == 1) {
        return "参与人员";
      } else if (data == 2) {
        return "观摩人员";
      }
    },
    rankingfun(data) {
      if (data == 1) {
        return "公司第一名";
      } else if (data == 2) {
        return "公司第二名";
      } else if (data == 3) {
        return "公司第三名";
      } else if (data == 4) {
        return "通报表扬";
      }
    },
    cancel() {
      this.dialogVisible2 = false;
      this.$refs.addForm.resetFields();
      // this.createForm.remark = ''
      this.addForm = {
        activityTime: "",
        activityType: "",
        activityTypeNum: "",
        content: "",
        participatingRole: "",
        participatingRoleNum: "",
        ranking: "",
        rankingNum: "",
        remark: "",
      };
    },
    currentChange(pageNo) {
      this.pageNo = pageNo;
      this.getActivityList();
    },
    // 序号-页面切换递增
    indexAdd(index) {
      return index + 1 + (this.pageNo - 1) * this.pageSize;
    },
    addActivity() {
      this.$refs.addForm.validate(async (valid) => {
        if (valid) {
          const res = await addActivity({
            activityTime: this.addForm.activityTime,
            activityType: this.addForm.activityTypeNum,
            content: this.addForm.content,
            participatingRole: this.addForm.participatingRoleNum,
            ranking: this.addForm.rankingNum,
            remark: this.addForm.remark,
          });
          if (res.code == 200) {
            this.$message({
              message: "创建成功",
              type: "success",
            });
            this.dialogVisible2 = false;
            this.getActivityList();
            this.$refs.addForm.resetFields();
            this.addForm = {
              activityTime: "",
              activityType: "",
              activityTypeNum: "",
              content: "",
              participatingRole: "",
              participatingRoleNum: "",
              ranking: "",
              rankingNum: "",
              remark: "",
            };
          }
          console.log("res", res);
        } else {
          return false;
        }
      });
    },
    async getActivityList() {
      const res = await activityList({
        pageNo: this.pageNo,
        pageSize: this.pageSize,
        activityStartTime: this.findMsg.activityDate[0],
        activityEndTime: this.findMsg.activityDate[1],
        activityType: this.findMsg.activityTypeNum,
        dept: this.findMsg.dept,
        emplName: this.findMsg.emplName,
        participatingRole: this.findMsg.participatingRoleNum,
        secondDept: this.findMsg.secondDept,
        team: this.findMsg.team,
      });
      if (res.code == 200) {
        this.activityList = res.data.list;
        this.total = res.data.total;
      }
      console.log("this.activityList", this.activityList);
    },
    query() {
      this.getActivityList();
    },
    reset() {
      this.findMsg.emplName = "";
      this.findMsg.dept = "";
      this.findMsg.secondDept = "";
      this.findMsg.team = "";
      this.findMsg.activityType = "";
      this.findMsg.activityTypeNum = "";
      this.findMsg.participatingRole = "";
      this.findMsg.participatingRoleNum = "";
      this.findMsg.activityDate = "";
    },
    findType(e) {
      this.findMsg.activityTypeNum = e;
    },
    findRole(e) {
      this.findMsg.participatingRoleNum = e;
    },
    changeType(e) {
      this.addForm.activityTypeNum = e;
    },
    changeRole(e) {
      this.addForm.participatingRoleNum = e;
    },
    changeRanking(e) {
      this.addForm.rankingNum = e;
    },
  },
};
</script>

<style lang="scss" scoped>
.c-main-make {
  margin-left: 35px;
  height: auto;
  background: #fff;
  margin-right: 35px;
  margin-bottom: 35px;
  position: relative;
  // overflow: hidden;
  border: 1px #dcdee0 solid;
}
.c-main-show {
  margin-left: 35px;
  height: auto;
  background: #fff;
  margin-right: 35px;
  margin-bottom: 35px;
  position: relative;
  // overflow: hidden;
  border: 1px #dcdee0 solid;
}
.title-text {
  width: 100%;
  height: 50px;
  border-bottom: 1px #dcdee0 solid;
  font-family: "微软雅黑 Bold", "微软雅黑 Regular", 微软雅黑, sans-serif;
  font-weight: 700;
  color: #666666;
  line-height: 50px;
  padding-left: 25px;
}
.main-scroll {
  height: 1000px;
  // overflow-y: scroll;
}
.pagination {
  display: flex;
  justify-content: end;
}
.box-card {
  margin-bottom: 20px;
}
.el-input {
  width: 250px;
}
.el-select {
  width: 250px;
}
//  .el-tooltip__popper{
//         max-width:20%;
//     }
//     .el-tooltip__popper,.el-tooltip__popper.is-dark{
//         background:rgb(48, 65, 86) !important;
//         color: #fff !important;
//         line-height: 24px;
//     }
</style>
